#ifndef UHTTPCLIENT_H
#define UHTTPCLIENT_H

#include "utkcore_global.h"
#include "uhttpinterface.h"

#include <QObject>
#include <QUrlQuery>

class UHttpClientPrivate;
class UTKCORE_EXPORT UHttpClient : public QObject, public HttpInterface
{
public:
    static UHttpClient* instance();

    bool getSync(const QString &url, QByteArray &resopnse, const QUrlQuery &urlQuery = QUrlQuery()) override;

    void getAsync(const QString &url, std::function<void (int, QByteArray)> resopnse,
                  const QUrlQuery &urlQuery = QUrlQuery()) override;

    void getAsync(const QString &url, std::function<void (int, QByteArray)> progress,
                  std::function<void (int, QByteArray)> finished, const QUrlQuery &urlQuery = QUrlQuery()) override;

    bool postSync(const QUrl &url, const QByteArray &data, QByteArray &result) override;

    void postAsync(const QUrl &url, const QByteArray &data, std::function<void (int, QByteArray)> resopnse) override;

    bool putSync(const QUrl &url, const QByteArray &data, QByteArray &result) override;

    void putAsync(const QUrl &url, const QByteArray &data, std::function<void (int, QByteArray)> resopnse) override;

    void setTimeOut(int timeout) override;

    void cancelRequest() override;

    bool uploadFile(const QUrl &url, const QString &filePath) override;

    bool downloadFile(const QUrl &url, const QString &filePath, std::function<void(int)> resopnse) override;

private:
    explicit UHttpClient(QObject* parent = nullptr);
    ~UHttpClient();

    Q_DISABLE_COPY(UHttpClient)
    QScopedPointer<UHttpClientPrivate> d_ptr;
    Q_DECLARE_PRIVATE(UHttpClient)
};

#endif // UHTTPCLIENT_H
